﻿using CarRental.DataAccessLayer;
using CarRental.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarRental.Account {
    public partial class UserLst : System.Web.UI.Page {
        Wcf _wcf = new Wcf();

        protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {
                ddlUserType.DataSource = new CarRental.Helpers.OptionItems.UserTypeLst();
                ddlUserType.DataValueField = "Key";
                ddlUserType.DataTextField = "Title";

                ddlUserType.DataBind();
            }
          
        }

        private void GridRefresh() {
            var lst = _wcf.GetUser().Where(w => w.user_type == (ddlUserType.SelectedValue ?? "")).ToList<user>();
            gvUser.DataSource = lst;
            gvUser.DataBind();

            //gvUser.Columns[1].ItemStyle.Width = 0;
        }

        protected void btnSearch_Click(object sender, EventArgs e) {
            //EntityDataSource
            EntityDataSource.WhereParameters.Clear();
            EntityDataSource.AutoGenerateWhereClause = true;
            EntityDataSource.WhereParameters.Add("user_type", TypeCode.String, ddlUserType.SelectedValue);
            
        }

        //protected void gvUser_RowCommand(Object sender, GridViewCommandEventArgs e) {
        //    if (e.CommandName == "Edit") {
        //        int index = Convert.ToInt32(e.CommandArgument);
        //        GridViewRow row = gvUser.Rows[index];
        //        //int ServerID = Convert.ToInt32(gvUser.DataKeys[index].Value);
        //        var rowView = row.Cells[0];
        //        var rowView1 = row.Cells[0];
        //        var rowView2 = row.Cells[1];
        //        var rowView3 = row.Cells[2];
        //        var rowView4 = row.Cells[3];
        //        var rowView5 = row.Cells[4];
        //    }
        //} 
    }
}